public class Serializer
extends java.lang.Object
Serializer is powerful utility class that allows you to serialize any object in Java using universal protocol system.
This system is generating code similar to JSON called SerialX but unlike JSON, SerialX is based on determinate order of arguments.
Also works with regular Java Base64 serialization.
Note: Since 1.1.5 this is an new, improved and more powerful JSON!| Modifier and Type | Class and Description |
|---|---|
static class |
Serializer.NULL
This is a "dummy" class that
Serializer uses internally as an OOP programmatic interpretation of null. |
static class |
Serializer.ProtocolRegistry
ProtocolRegistry, place to register protocols!
|
| Modifier and Type | Field and Description |
|---|---|
static java.text.DecimalFormat |
decimalFormatter
Decimal formatter to format decimal numbers (double, float) with during serialization!
|
static boolean |
generateComments
Set this on true and program will generate comments and report!
|
static java.util.Map<java.lang.String,java.lang.Object> |
globalVariables
Map with global variables, accessible for any serialized content (key is variable name, value is vale).
|
static Serializer.ProtocolRegistry |
PROTOCOL_REGISTRY
This is serialization protocol registry.
|
static boolean |
serializeStringNormally
Set this on true and
String will be serialized normally, for instance "Hello world!" |
static boolean |
useProtocolIfCan
Set this on true to force program to use SerializationProtocol also on java.io.Serializable objects.
|
static java.lang.Object |
VOID
This object is not going to be loaded!
|
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
Clone(T obj) |
static java.lang.String |
Code(java.lang.String code) |
static java.lang.String |
Comment(java.lang.String comment) |
static <T> T |
Instantiate(java.lang.Class<T> cls) |
static java.lang.Object |
InvokeStaticFunc(java.lang.Class<?> cls,
java.lang.String name,
java.lang.Object... args) |
static java.lang.String |
LoadFileToString(java.io.File f) |
static java.lang.String |
LoadFileToString(java.io.File f,
int endlMode) |
static Scope |
LoadFrom(java.io.File file) |
static <T> T |
LoadFrom(java.io.File file,
int index) |
static <T> T |
LoadFrom(java.io.File file,
java.lang.String varName) |
static Scope |
LoadFrom(java.lang.CharSequence str) |
static <T> T |
LoadFrom(java.lang.CharSequence str,
int index) |
static <T> T |
LoadFrom(java.lang.CharSequence str,
java.lang.String varName) |
static Scope |
LoadFrom(java.io.Reader reader) |
static <T> T |
LoadFrom(java.io.Reader reader,
int index) |
static <T> T |
LoadFrom(java.io.Reader reader,
java.lang.String varName) |
static Scope |
LoadFromString(java.lang.String str)
Deprecated.
|
static java.lang.String |
SerializeClassic(java.io.Serializable obj) |
static <A extends java.lang.Appendable> |
SerializeTo(A source,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static <A extends java.lang.Appendable> |
SerializeTo(A source,
java.lang.Object... objs) |
static <A extends java.lang.Appendable> |
SerializeTo(A source,
Scope scope) |
static void |
SerializeTo(boolean append,
java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static void |
SerializeTo(boolean append,
java.io.File f,
java.lang.Object... objs) |
static void |
SerializeTo(java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static void |
SerializeTo(java.io.File f,
java.lang.Object... objs) |
static void |
SerializeTo(java.io.File f,
Scope scope) |
static java.lang.String |
SerializeToString(java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static java.lang.String |
SerializeToString(java.lang.Object... objs) |
static java.lang.String |
SerializeToString(Scope scope) |
static java.lang.String |
StaticMember(java.lang.Class<?> cls,
java.lang.String staticMethodName,
java.lang.Object... args) |
static java.lang.Class<?>[] |
ToClasses(java.lang.Object... objs) |
static java.lang.Object |
UnserializeClassis(java.lang.String objStr) |
static <T> java.lang.String |
Var(java.lang.String name,
T value) |
static <T> java.lang.String |
Var(java.lang.String name,
T value,
boolean isValue) |
public static final Serializer.ProtocolRegistry PROTOCOL_REGISTRY
Collection, Map and CharSequence!public static boolean useProtocolIfCan
public static boolean generateComments
public static boolean serializeStringNormally
String will be serialized normally, for instance "Hello world!" and not using protocols or java Base64! public static java.text.DecimalFormat decimalFormatter
DecimalFormat will round decimal numbers to 3 decimal places (format pattern #.###)!
Set this on null and decimal numbers will not be formated! Do this when you need accuracy!public static java.util.Map<java.lang.String,java.lang.Object> globalVariables
public static final java.lang.Object VOID
Serializer interprets void during unzerializtion.public static <T> java.lang.String Var(java.lang.String name,
T value)
name - | Name of variable.value - | Value of variable.public static <T> java.lang.String Var(java.lang.String name,
T value,
boolean isValue)
name - | Name of variable.value - | Value of variable.isValue - | True if variables value supposed to by visible also during value loading.public static java.lang.String StaticMember(java.lang.Class<?> cls,
java.lang.String staticMethodName,
java.lang.Object... args)
cls - | Class to invoke static member on!staticMethodName - | Name of static member!args - | Arguments of method (use this only if you are invoking method no field)!public static java.lang.String Comment(java.lang.String comment)
comment - | The comment...public static java.lang.String Code(java.lang.String code)
code - | Code to convert in to SerialX code form.public static void SerializeTo(java.io.File f,
java.lang.Object... objs)
f - | File to write in. This must be a text file (recommended extension .srlx).objs - | Objects to serialize using SerialX.public static void SerializeTo(boolean append,
java.io.File f,
java.lang.Object... objs)
append - | When true, the new objects will be appended to files content (same objects will be also appended if there are some)!f - | File to write in. This must be a text file (recommended extension .srlx).objs - | Objects to serialize using SerialX.public static void SerializeTo(java.io.File f,
Scope scope)
f - | File to write in. This must be a text file (recommended extension .srlx).scope - | Scope with variables and values to serialize!public static void SerializeTo(java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
f - | File to write in. This must be a text file (recommended extension .srlx).variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static void SerializeTo(boolean append,
java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
append - | When true, the new objects will be appended to files content (same objects will be also appended if there are some)!f - | File to write in. This must be a text file (recommended extension .srlx).variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static java.lang.String SerializeToString(java.lang.Object... objs)
objs - | Objects to serialize using SerialX.public static java.lang.String SerializeToString(Scope scope)
scope - | Scope with variables and values to serialize!public static java.lang.String SerializeToString(java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static <A extends java.lang.Appendable> A SerializeTo(A source,
java.lang.Object... objs)
source - | Source Appendable to serialize objects into!objs - | Objects to serialize using SerialX.Appendable with objects serialized in SerialX code.public static <A extends java.lang.Appendable> A SerializeTo(A source,
Scope scope)
source - | Source Appendable to serialize variables and objects into!scope - | Scope with variables and values to serialize!Appendable with variables and objects serialized in SerialX code.public static <A extends java.lang.Appendable> A SerializeTo(A source,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
source - | Source Appendable to serialize variables and objects into!variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.Appendable with variables and objects serialized in SerialX code.public static java.lang.String SerializeClassic(java.io.Serializable obj)
throws java.lang.Exception
obj - | Object to serialize using classic Java serialization.
Note: Slash will be replaced by back slash and Base64 padding with dash due to prevent conflict with SerialX syntax!java.lang.Exception - - if an I/O error occurs while writing stream headerjava.lang.Base64public static java.lang.String LoadFileToString(java.io.File f)
f - | Source file.public static java.lang.String LoadFileToString(java.io.File f,
int endlMode)
f - | Source file.endlMode - | 0 = no line brakes, 1 = always line brakes, 2 = line break only when contains with "//"! LoadFileToString(File) which is doing this automatically!public static Scope LoadFrom(java.io.File file)
@Deprecated public static Scope LoadFromString(java.lang.String str)
LoadFrom(CharSequence) instead!public static Scope LoadFrom(java.lang.CharSequence str)
public static Scope LoadFrom(java.io.Reader reader)
public static <T> T LoadFrom(java.io.File file,
int index)
file - | File with SerialX content.index - | Index of value to get from lowest Scope.public static <T> T LoadFrom(java.lang.CharSequence str,
int index)
str - | Any CharSequence with SerialX content.index - | Index of value to get from lowest Scope.public static <T> T LoadFrom(java.io.Reader reader,
int index)
reader - | Any Reader with SerialX content.index - | Index of value to get from lowest Scope.public static <T> T LoadFrom(java.io.File file,
java.lang.String varName)
file - | File with SerialX content.varName - | Name of variable to load!public static <T> T LoadFrom(java.lang.CharSequence str,
java.lang.String varName)
str - | Any CharSequence with SerialX content.varName - | Name of variable to load!public static <T> T LoadFrom(java.io.Reader reader,
java.lang.String varName)
reader - | Any Reader with SerialX content.varName - | Name of variable to load!public static java.lang.Object UnserializeClassis(java.lang.String objStr)
throws java.lang.Exception
objStr - | String to unserialize by classic Java serialization.
Note: Backslashes will be replaced by regular slashes and dashes with Base64 padding due to compatibility with SerialX syntax.java.io.IOException - - if an I/O error occurs while reading stream header.java.lang.ClassNotFoundException - - Class of a serialized object cannot be found.java.lang.ExceptionBase64public static java.lang.Object InvokeStaticFunc(java.lang.Class<?> cls,
java.lang.String name,
java.lang.Object... args)
throws java.lang.reflect.InvocationTargetException
cls - | Class to invoke method from.name - | Name of public static method to be called.args - | Arguments of method. Arguments should be certain if method is overloaded!VOID if return type of method is void. If something when wrong you will be notified and null will be returned.java.lang.reflect.InvocationTargetException - if called method throws and exception while calling!public static <T> T Clone(T obj)
obj - | Object to clone.SerializationProtocol or the same object as inserted one if cloning is not possible, for instance when protocol was not found and object is not instance of Cloneable.
This clone function will always prioritized the Protocol variation, regular cloning is used only when there is no protocol registered or exception occurs. public static <T> T Instantiate(java.lang.Class<T> cls)
throws java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException
cls - | Class to instantiate.java.lang.NoSuchMethodException - if there is no public constructor!java.lang.reflect.InvocationTargetException - if called constructor throws and exception!public static java.lang.Class<?>[] ToClasses(java.lang.Object... objs)
objs - | Array of objects.